package znbkTestPaperXtfx;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;
import com.example.lancooznbk.utils.DensityUtils;
import com.example.lancooznbk.view.base.BaseActivity;
import com.example.lancooznbk.view.widget.QuesIndexView;
import com.example.lancooznbk.view.widget.ScaleButton;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import lancooControl.Control;
import lancooCustomListview.BounceScrollView;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperInfor.ZnbkPaperInfor;
import znbkTestPaperRdqh.ZnbkPaperRdqhInfor;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperRdqh.fragmentAdapter.WeekAscensionPaperFragmentAdapter;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;
import znbkTestPaperXtfx.fragmentAdapter.SystemReviewPaperFragmentAdapter;
import znbkTestPaperXtfx.getDiagnosticReportInfo.GetDiagnosticReportEntity;
import znbkTestPaperXtfx.knowledgeList.KnowledgesListActivity;
import znbkTopicType.MyGridView;

import static znbkTestPaperRdqh.activity.WeekAscensionPaperActivity.mEntityRdqh;
import static znbkTestPaperXtfx.activity.SystemReviewPaperActivity.mEntityXtfx;

/**
 * Created by Administrator on 2018\4\2 0002.
 */

public class AnswerSheet extends PopupWindow {

    private View mMenuView;
    private ScaleButton mSBtnClose;
    private TextView TvTitle;
    private LinearLayout mLayoutDetails;
    private MyGridView mGViewDetails;
    private LinearLayout mLayoutPracticeReport;
    private BounceScrollView mScrollView;
    private MyGridAdapter adapter;
    private Activity mContext;
    private final RelativeLayout[] rLayoutQuesList;
    private int mCurPageIndex;
    private int mCurQuesIndex;

    private final LinearLayout[] mLayoutQuesTitle;
    private final ImageView[] mIvCircle;
    private final TextView[] mTvTypeName;

    private TextView mTvAnswerTime;
    private TextView mTvAnswerAccuracy;
    private TextView mTvAnswerAccuracyDetail;
    private ScaleButton mSBtnCheckKnowledges;

    private int mPaperFrom;

    public AnswerSheet(final Activity context, int curPageIndex, int curQuesIndex, int paperFrom) {
        super(context);
        this.mCurPageIndex = curPageIndex;
        this.mCurQuesIndex = curQuesIndex;
        this.mPaperFrom = paperFrom;
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.answer_sheet, null);

        //核心代码.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        mContext = context;

        mSBtnClose = (ScaleButton) mMenuView.findViewById(R.id.sbtn_close);

        mScrollView = (BounceScrollView) mMenuView.findViewById(R.id.scroll_ques_index);

        RelativeLayout relToolbar = (RelativeLayout) mMenuView.findViewById(R.id.rlayout_back);
        int statusBarHeight = ((BaseActivity) context).getStatusBarHeight();
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) relToolbar.getLayoutParams();
        layoutParams.setMargins(0,statusBarHeight,0,0);

        mSBtnClose.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //销毁弹出框
                dismiss();
            }
        });


        //答题卡标题文字
        TvTitle = (TextView) mMenuView.findViewById(R.id.tv_tittle);
        mLayoutDetails = (LinearLayout) mMenuView.findViewById(R.id.layout_details);

        /*
        * 作答时间
        * */
        mTvAnswerTime = (TextView) mMenuView.findViewById(R.id.tv_answerTime);

        /*
        * 正确率
        * */
        mTvAnswerAccuracy = (TextView) mMenuView.findViewById(R.id.tv_answerAccuracy);

        /*
        * 正确率详情
        * */
        mTvAnswerAccuracyDetail = (TextView) mMenuView.findViewById(R.id.tv_answerAccuracyDetail);

        mSBtnCheckKnowledges = (ScaleButton) mMenuView.findViewById(R.id.sbtn_checkKnowledges);
        mSBtnCheckKnowledges.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ToastUtils.showShort("进入考点列表");
                mContext.startActivity(new Intent(mContext, KnowledgesListActivity.class));
            }
        });
        mGViewDetails = (MyGridView) mMenuView.findViewById(R.id.gv_details);
        //练习报告自评内容
        mLayoutPracticeReport = (LinearLayout) mMenuView.findViewById(R.id.layout_practiceReport);

        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.Popupwindow);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        View mViewAnswerSheetDash = (View) mMenuView.findViewById(R.id.view_answerSheetDash);
        LinearLayout LayoutAnswerSheet = (LinearLayout) mMenuView.findViewById(R.id.layout_answer_sheet);

        /*
        * 获取试题总数：PaperCount
        * */
        int PaperCount = -1;
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
            PaperCount = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().size();
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            PaperCount = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().size();
        }


        mLayoutQuesTitle = new LinearLayout[PaperCount];
        mIvCircle = new ImageView[PaperCount];
        mTvTypeName = new TextView[PaperCount];
        rLayoutQuesList = new RelativeLayout[PaperCount];
        for(int i=0;i<PaperCount;i++){

            /*
            * 试题位置编号：QuesNumber
            * 试题题型：TypeName
            * */
            int QuesNumber = -1;
            String TypeName = "";
            if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
                 QuesNumber = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getDetail().get(i).getIndex();
                 TypeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getTypeName();
            }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
                 QuesNumber = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getDetail().get(i).getIndex();
                 TypeName = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(i).getTypeName();
            }

            mLayoutQuesTitle[i] = new LinearLayout(mContext);
            mLayoutQuesTitle[i].setOrientation(LinearLayout.HORIZONTAL);

            mIvCircle[i] = new ImageView(mContext);
            mIvCircle[i].setBackgroundResource(R.drawable.znbk_blue_circle);
            LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(10,10);
            mIvCircle[i].setLayoutParams(mLayoutParams);

//            LayoutAnswerSheet.addView(mIvCircle[i]);
            mLayoutQuesTitle[i].addView(mIvCircle[i]);

            mTvTypeName[i] = new TextView(mContext);
            mTvTypeName[i].setText(Html.fromHtml("<font color='#000000'><middle><middle>"+"第"+String.valueOf(QuesNumber)+"大题"+"</middle></middle></font>"+
                    "<font color='#000000'><middle><middle>"+"&nbsp;&nbsp;&nbsp;"+TypeName+"</middle></middle></font>"));
            mTvTypeName[i].setPadding(DensityUtils.dp2px(mContext,15), 0,0,0);
//            LayoutAnswerSheet.addView(mTvTypeName[i]);
            mLayoutQuesTitle[i].addView(mTvTypeName[i]);
            mLayoutQuesTitle[i].setGravity(Gravity.CENTER_VERTICAL);
            mLayoutQuesTitle[i].setPadding(0, DensityUtils.dp2px(mContext,15),0,DensityUtils.dp2px(mContext,15));
            LayoutAnswerSheet.addView( mLayoutQuesTitle[i]);


            rLayoutQuesList[i] = new RelativeLayout(mContext);

            /*
            * 试题对应的小题数量：smallQuesTotalItemCount
            * */
            int smallQuesTotalItemCount = -1;
            if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
                if(TypeName.equals("匹配题")){
                    smallQuesTotalItemCount = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getTotalItemCount();
                }else{
                    smallQuesTotalItemCount = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().size();
                }
            }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
                smallQuesTotalItemCount = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().size();
            }

            DisplayMetrics dm = new DisplayMetrics();
            context.getWindowManager().getDefaultDisplay().getMetrics(dm);
            int width = dm.widthPixels;
            int height = dm.heightPixels;

            final QuesIndexView[] quesIndexViews = new QuesIndexView[smallQuesTotalItemCount];

            int k = -1;
            for(int j = 0;j<smallQuesTotalItemCount;j++){
                quesIndexViews[j] = new QuesIndexView(mContext);
                quesIndexViews[j].setTag(j);
                if ( i == mCurPageIndex && j == mCurQuesIndex){
                    quesIndexViews[j].setQuesIndexChecked(true);
                    mScrollView.post(new Runnable() {
                        @Override
                        public void run() {
                            // int[] location = new int[2];
                            int top1 = mTvTypeName[mCurPageIndex].getTop();
                            top1 -= 10;
                            if (top1 < 0){
                                top1 = 0;
                            }
                            mScrollView.scrollTo(0,top1);
                        }
                    });

                }

                if(GetStuAnswerState()==3) {
                    //已提交
                    if(GetIsAnswered(i,j)){

                        if(GetStuAnswer(i,j).equals(GetAnswer(i,j))||GetStuAssess(i,j).equals("优秀")
                                ||GetStuAssess(i,j).equals("一般")||GetStuAssess(i,j).equals("合格")){
                            quesIndexViews[j].setQuesIndexStatus(QuesIndexView.STATUS_RIGHT);
                        }else{
                            quesIndexViews[j].setQuesIndexStatus(QuesIndexView.STATUS_WRONG);
                        }
                    }else{
                        quesIndexViews[j].setQuesIndexStatus(QuesIndexView.STATUS_NO_ANSWER);
                    }
                }else{
                    //未提交
                    if(GetIsAnswered(i,j)){
                        quesIndexViews[j].setQuesIndexStatus(QuesIndexView.STATUS_ANSWER);
                    }else{
                        quesIndexViews[j].setQuesIndexStatus(QuesIndexView.STATUS_NO_ANSWER);
                    }
                }


                quesIndexViews[j].setQuesIndexText(String.valueOf(j + 1));
                final int finalI = i;
                final int finalJ = j;
                quesIndexViews[j].setQuesIndexClickListener(new QuesIndexView.QuesIndexClickListener() {
                    @Override
                    public void onClick(View v) {

                        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
                            Log.e("=====finalJ===xtfx=====", "===aaaaaa====" + finalJ);
                            SystemReviewPaperActivity.mVp.setCurrentItem(finalI);
                            Fragment fragment = (Fragment) ((SystemReviewPaperFragmentAdapter)
                                    SystemReviewPaperActivity.mVp.getAdapter()).instantiateItem( SystemReviewPaperActivity.mVp, finalI);
                            ViewPager childViewPage = (ViewPager) fragment.getView().findViewById(R.id.viewpage_answer);
                            childViewPage.setCurrentItem(finalJ);
                        }else{
                            Log.e("=====finalJ===rdqh=====", "===aaaaaa====" + finalJ);
                            WeekAscensionPaperActivity.mVp.setCurrentItem(finalI);
                            Fragment fragment = (Fragment) ((WeekAscensionPaperFragmentAdapter)
                                    WeekAscensionPaperActivity.mVp.getAdapter()).instantiateItem( WeekAscensionPaperActivity.mVp, finalI);
                            ViewPager childViewPage = (ViewPager) fragment.getView().findViewById(R.id.viewpage_answer);
                            childViewPage.setCurrentItem(finalJ);
                        }


                        dismiss();
                    }
                });

                RelativeLayout.LayoutParams btnParams = new RelativeLayout.LayoutParams(width / 9, width / 9);

                if (j % 5 == 0) {
                    k++;
                }

                btnParams.leftMargin = ((width) / 5) * (j % 5) + (width / 5 - width / 9) / 2;   //横坐标定位
                btnParams.topMargin = 20 + (width / 9 + 20) * k;   //纵坐标定位

                rLayoutQuesList[i].addView(quesIndexViews[j],btnParams);
            }

            LayoutAnswerSheet.addView(rLayoutQuesList[i]);

        }

        int ww = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
        int hh = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
        LayoutAnswerSheet.measure(ww,hh);
        int height = LayoutAnswerSheet.getMeasuredHeight();
        RelativeLayout.LayoutParams mLayoutParams = new RelativeLayout.LayoutParams(1,height);
        mLayoutParams.setMargins(4, DensityUtils.dp2px(mContext,25),0,0);
        mViewAnswerSheetDash.setLayoutParams(mLayoutParams);


        /*********************************************/
        /*********************************************/
        if(GetStuAnswerState()!=3){
            TvTitle.setText("答题卡");
            mLayoutPracticeReport.setVisibility(View.GONE);
        }else {

            /*
            * 获取诊断报告
            * */
            GetDiagnosticReport();
            new Thread(new AccessNetwork(h)).start();

            TvTitle.setText("练习报告");
            mLayoutPracticeReport.setVisibility(View.VISIBLE);
        }
    }

    /*
    * 获取试题作答情况
    * */
    private int GetStuAnswerState(){
        int AnswerState = -1;
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            AnswerState = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            AnswerState = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
        }
        return AnswerState;
    }

    /*
    * 获取正确答案
    * */
    private String GetAnswer(int i,int j){
        String Answer = "";
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            String TypeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getTypeName();
            if(TypeName.equals("匹配题")){
                String AllAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(0).
                        getSubChildList().get(0).getSubChildAnswer();
                Answer = Control.returnArray(AllAnswer,"$、",2)[j];
            }else {
                Answer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                        getSubChildList().get(0).getSubChildAnswer();
            }
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            Answer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                    getSubChildList().get(0).getSubChildAnswer();
        }
        return Answer;
    }

    /*
    * 获取学生答案
    * */
    private String GetStuAnswer(int i,int j){
        String StuAnswer = "";
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            String TypeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getTypeName();
            if(TypeName.equals("匹配题")){
                String AllStuAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(0).
                        getSubChildList().get(0).getSubChildStuAnswer();
                if(AllStuAnswer.equals("")){
                    StuAnswer = "";
                }else {
                    StuAnswer = Control.returnArray(AllStuAnswer, "$、", 2)[j];
                }
            }else {
                StuAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                        getSubChildList().get(0).getSubChildStuAnswer();
            }
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            StuAnswer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                    getSubChildList().get(0).getSubChildStuAnswer();
        }
        return StuAnswer;
    }

    /*
    * 获取学生自评
    * */
    private String GetStuAssess(int i,int j){
        String StuAssess = "";
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            String TypeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getTypeName();
            if(TypeName.equals("匹配题")){
                StuAssess = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(0).
                        getSubChildList().get(0).getSubChildStuAssess();
            }else {
                StuAssess = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                        getSubChildList().get(0).getSubChildStuAssess();
            }
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            StuAssess = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                    getSubChildList().get(0).getSubChildStuAssess();
        }
        return StuAssess;
    }

    /*
    * 获取学生纸面作答照片
    * */
    private String GetUpLoadPath(int i,int j){
        String UpLoadPath = "";
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            String TypeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getTypeName();
            if(TypeName.equals("匹配题")){
                UpLoadPath  = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(0).
                        getSubChildList().get(0).getUpLoadPath();
            }else {
                UpLoadPath = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                        getSubChildList().get(0).getUpLoadPath();
            }
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            UpLoadPath = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(i).getChildList().get(j).
                    getSubChildList().get(0).getUpLoadPath();
        }
        return UpLoadPath;
    }

    /*
    * 判断当前试题是否已作答
    * */
    private boolean GetIsAnswered(int i,int j){
        boolean IsAnswered = false;

        if(GetStuAnswer(i,j).equals("")&GetStuAssess(i,j).equals("")&GetUpLoadPath(i,j).equals("")){
            IsAnswered = false;
        }else{
            IsAnswered = true;
        }
        return IsAnswered;
    }


    protected class MyGridAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            int Count = -1;
            if(arrayKnowledgeNames.size()>6){
                Count = 6;
            }else{
                Count = arrayKnowledgeNames.size();
            }
            return Count;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View view = View.inflate(mContext, R.layout.list_item_main, null);
            TextView mTvScore = (TextView) view.findViewById(R.id.tv_score);
            /*
            * 计算当前得分是进步还是退步
            * */
            double changeScore = 0;
            int changeFlag = 0;
            if(Double.valueOf(arrayLastScores.get(position))>Double.valueOf(arrayOriginalScores.get(position))){
                 changeScore = Double.valueOf(arrayLastScores.get(position))-Double.valueOf(arrayOriginalScores.get(position));
                changeFlag = 1;
            }else if(Double.valueOf(arrayLastScores.get(position))==Double.valueOf(arrayOriginalScores.get(position))){
                changeScore = 0;
                changeFlag = 0;
            }else if(Double.valueOf(arrayLastScores.get(position))<Double.valueOf(arrayOriginalScores.get(position))){
                 changeScore = Double.valueOf(arrayOriginalScores.get(position))-Double.valueOf(arrayLastScores.get(position));
                changeFlag = -1;
            }
            if(changeFlag==-1){
                Drawable drawable = mContext.getResources().getDrawable(R.mipmap.znbk_icon_score_down);
                drawable.setBounds(0,0,drawable.getMinimumHeight(),drawable.getMinimumHeight());
                mTvScore.setCompoundDrawables(null,null,drawable,null);
            }else if(changeFlag==0){
                mTvScore.setCompoundDrawables(null,null,null,null);
            }else if(changeFlag==1){
                Drawable drawable = mContext.getResources().getDrawable(R.mipmap.znbk_icon_score_up);
                drawable.setBounds(0,0,drawable.getMinimumHeight(),drawable.getMinimumHeight());
                mTvScore.setCompoundDrawables(null,null,drawable,null);
            }
            String strChangeScore = "";
            if(changeScore==0){
                strChangeScore = "0";
            }else{
                strChangeScore = String.valueOf(changeScore);
            }
            mTvScore.setText(strChangeScore);

            TextView mTvKnowledge = (TextView) view.findViewById(R.id.tv_knowledge);
            mTvKnowledge.setText(arrayKnowledgeNames.get(position));

            return view;
        }
    }


    private String htmlStr = "";
    private void GetDiagnosticReport(){

        String PaperId = "";
        if(mPaperFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            PaperId = ZnbkPaperXtfxInfor.PaperId;
        }else if(mPaperFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            PaperId = ZnbkPaperRdqhInfor.PaperId;
        }

        String url = ZnbkPaperInfor.BaseHttpAdress + "api/ZNBK/W_ZNBK_GetDiagnosticReportInfo?stuId="+ UserInfo.StuId+"&paperId="+PaperId;

        /**
         * OkHttpClient 的Get请求
         */

        //创建okHttpClient对象
        OkHttpClient mOkHttpClient = new OkHttpClient();
        //创建一个Request
        final Request request = new Request.Builder()
                .url(url)
                .build();
        //new call
        Call call = mOkHttpClient.newCall(request);
        //请求加入调度
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
            }

            @Override
            public void onResponse(final Response response) throws IOException {
                htmlStr = response.body().string();
                Log.e("==wgl==", "" + htmlStr);
            }
        });
    }

    public static ArrayList<String> arrayKnowledgeNames = null;//知识点
    public static ArrayList<String> arrayLastScores=null;//当前得分
    public static ArrayList<String> arrayOriginalScores=null;//原始得分
    public static ArrayList<String> arrayRequiredScores=null;//标准得分
    //利用Handler更新UI
    final Handler h = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what==0x123&!htmlStr.equals("")){

                arrayKnowledgeNames = new ArrayList<>();//知识点
                arrayLastScores= new ArrayList<>();//当前得分
                arrayOriginalScores = new ArrayList<>();//原始得分
                arrayRequiredScores= new ArrayList<>();//标准得分

                Gson gson = new Gson();
                List<GetDiagnosticReportEntity> mEntityZdbg = gson.fromJson(htmlStr, new TypeToken<List<GetDiagnosticReportEntity>>(){}.getType());

                /*
                * 作答时间
                * */
                int useTime = mEntityZdbg.get(0).getDuration();
                int hour = useTime/3600;
                int minute = useTime/60%60;
                int second = useTime%60;
                String useTimeLong = "";
                if(hour>0){
                    useTimeLong = hour+"时"+minute+"分"+second+"秒";
                }else{
                    if(minute>0){
                        useTimeLong = minute+"分"+second+"秒";
                    }else{
                        useTimeLong = second+"秒";
                    }
                }
                mTvAnswerTime.setText("作答时间 "+useTimeLong);

                /*
                * 正确率
                * */
                mTvAnswerAccuracy.setText("正确率 "+mEntityZdbg.get(0).getPaperAnswerRate()+"%");
                mTvAnswerAccuracyDetail.setText("( "+mEntityZdbg.get(0).getTotalItemCount()+
                        "道题，作答正确"+mEntityZdbg.get(0).getRightItemCount()+
                        "道，自评正确"+mEntityZdbg.get(0).getAssessRightItemCount()+"道 ）");

                /*
                * 考点情况
                * */
                int knowledgesCount = mEntityZdbg.get(0).getKnowledges().size();
                for(int i=0;i<knowledgesCount;i++){
                    String knowledgeName = mEntityZdbg.get(0).getKnowledges().get(i).getKnowledgeName();
                    arrayKnowledgeNames.add(knowledgeName);
                    String LastScore= String.valueOf(mEntityZdbg.get(0).getKnowledges().get(i).getLastScore());
                    arrayLastScores.add(LastScore);
                    String OriginalScore = String.valueOf(mEntityZdbg.get(0).getKnowledges().get(i).getOriginalScore());
                    arrayOriginalScores.add(OriginalScore);
                    String RequiredScore = String.valueOf(mEntityZdbg.get(0).getKnowledges().get(i).getRequiredScore());
                    arrayRequiredScores.add(RequiredScore);
                }

                adapter = new MyGridAdapter();
                mGViewDetails.setAdapter(adapter);

            }
        }
    };


    class AccessNetwork implements Runnable{
        private Handler h;

        public AccessNetwork(Handler h) {
            super();
            this.h = h;
        }

        @Override
        public void run() {
            Message m = new Message();
            m.what = 0x123;
            h.sendMessage(m);
        }
    }


}